################################################################################
#
#               The Filibuster and Legislative Discussion
#
#                             Fu and Howell
#
#                                Nov 2022
#
################################################################################

library(tidyverse) 
library(data.table)
library(lubridate)
library(lfe)
library(stargazer)
library(ggthemes)

###################   Analysis 3: Judicial Nominees   #########################

 ### Read Data ###
setwd("~/Dropbox/FuHowell_Filibuster_Replication/data/")
jnomObamaCoded2 <- read_csv("jnomObamaCoded2.csv")
jnomObama_panel <- read_csv("jnomObama_panel.csv")
jnomObamaAll_panel <- read_csv("jnomObamaAll_panel.csv")
jnomBush_panel <- read_csv("jnomBush_panel.csv")



### Analysis ###

# Table 3: Discussion of Judicial Nominees and Elimination of the Filibuster in 2013
mod_jnom <- felm(log_word ~ noFilibuster + Level + same_state | speakerid2 | 0 | congress, data = jnomObama_panel)
mod_jnom_c <- felm(log_word ~ noFilibuster + same_state | speakerid2 | 0 | congress, data = jnomObama_panel[jnomObama_panel$Level == "Circuit", ])
mod_jnom_d <- felm(log_word ~ noFilibuster + same_state | speakerid2 | 0 | congress, data = jnomObama_panel[jnomObama_panel$Level == "District", ])

stargazer(mod_jnom, mod_jnom_c, mod_jnom_d,
          type = "text",
          omit.stat = c("adj.rsq", "f", "ser"),
          add.lines = list(c("Senator FE", "Yes", "Yes", "Yes"),
                           c("Unique Senator", "155", "155", "155"),
                           c("Unique Nominee", "323", "55", "268")))



### APPENDIX ###

# Table A.12: Unlogged Dependent Variable
mod_jnom_unlogged <- felm(word_count ~ noFilibuster + Level + same_state  | speakerid2 | 0 | congress, data = jnomObama_panel)
mod_jnom_c_unlogged <- felm(word_count ~ noFilibuster + same_state  | speakerid2 | 0 | congress, data = jnomObama_panel[jnomObama_panel$Level == "Circuit", ])
mod_jnom_d_unlogged <- felm(word_count ~ noFilibuster + same_state  | speakerid2 | 0 | congress, data = jnomObama_panel[jnomObama_panel$Level == "District", ])

stargazer(mod_jnom_unlogged, mod_jnom_c_unlogged, mod_jnom_d_unlogged,
          type = "text",
          omit.stat = c("adj.rsq", "f", "ser"),
          add.lines = list(c("Senator FE", "Yes", "Yes", "Yes"),
                           c("Unique Senator", "155", "155", "155"),
                           c("Unique Nominee", "323", "55", "268")))



# Table A.13: Legislative Discussion of Judicial Nominees in Appellate Courts
jnomObama_panel_c_ex <- jnomObama_panel %>%
  filter(Level == "Circuit") %>%
  filter(!Judge %in% c("Patricia Millett", "Robert L. Wilkins", "Cornelia Pillard"))

mod_jnom_c_ex <- felm(log_word ~ noFilibuster + same_state | speakerid2 | 0 | congress, data = jnomObama_panel_c_ex)

stargazer(mod_jnom_c, mod_jnom_c_ex,
          type = "text",
          omit.stat = c("adj.rsq", "f", "ser"),
          add.lines = list(c("Senator FE", "Yes", "Yes"),
                           c("Unique Senator", "155", "155"),
                           c("Unique Nominee", "55", "52")))



# Table A.14: Legislative Discussion of all Obama’s Judicial Nominees 
#            (Failed Nominees Included)
mod_jnom <- felm(log_word ~ noFilibuster + Level + same_state | speakerid2 | 0 | congress, data = jnomObamaAll_panel)
mod_jnom_c_all <- felm(log_word ~ noFilibuster + same_state | speakerid2 | 0 | congress, data = jnomObamaAll_panel[jnomObamaAll_panel$Level == "Circuit", ])
mod_jnom_d_all <- felm(log_word ~ noFilibuster + same_state | speakerid2 | 0 | congress, data = jnomObamaAll_panel[jnomObamaAll_panel$Level == "District", ])


stargazer(mod_jnom, mod_jnom_c_all, mod_jnom_d_all,
          type = "text",
          omit.stat = c("adj.rsq", "f", "ser"),
          add.lines = list(c("Senator FE", "Yes", "Yes", "Yes"),
                           c("Unique Senator", "155", "155", "155"),
                           c("Unique Nominee", "380", "68", "312")))




# check number of nominees that during the last two years of Obama
# Figure A.3
jnomObamaCoded2 %>%
  mutate(ConfirmationYear = year(ConfirmationDate)) %>%
  group_by(ConfirmationYear, Level) %>%
  summarise(N = n()) %>%
  mutate(Level = ifelse(Level == "Circuit", "Appellate Courts", "District Courts")) %>%
  ggplot(aes(x = ConfirmationYear, y = N, fill = Level)) +
  geom_col() +
  facet_wrap(~Level, ncol = 2) +
  scale_fill_manual(values = c("black", "grey60")) +
  scale_x_continuous(breaks = c(2009:2016)) +
  labs(x = "Year", y = "Number of Nominees") +
  theme_few()

# check confirmation votes of nominees during the last two years of Obama
# Figure A.4
jnomObamaCoded2 %>%
  mutate(yay = str_split(ConfirmationVote, "-", simplify = T)[,1]) %>%
  mutate(yay = ifelse(yay == "unanimous consent" | yay == "voice vote", 100, yay)) %>%
  mutate(yay = as.numeric(yay)) %>%
  mutate(ConfirmationYear = year(ConfirmationDate)) %>%
  group_by(ConfirmationYear, Level) %>%
  summarise(yay_ave = mean(yay),
            number = n()) %>%
  mutate(Level = ifelse(Level == "Circuit", "Appellate Courts", "District Courts")) %>%
  ggplot(aes(x = ConfirmationYear, y = yay_ave, color = Level)) +
  geom_point(aes(size = number)) +
  geom_line(size = 1) +
  facet_wrap(~Level, ncol = 2) +
  scale_color_manual(values = c("black", "grey60")) +
  scale_x_continuous(breaks = c(2009:2016)) +
  scale_y_continuous(limits = c(75, 100)) +
  labs(x = "Year", y = "Average Yay Votes in Confirmation", size = "Number of Nominees") +
  theme_few()


# Table A.15: Considering lost control in Senate
mod_jnom_lost <- felm(log_word ~ noFilibuster + Level + same_state  | speakerid2 | 0 | congress, data = jnomObama_panel[jnomObama_panel$lost_control == 0,])
mod_jnom_c_lost <- felm(log_word ~ noFilibuster + same_state  | speakerid2 | 0 | congress, data = jnomObama_panel[jnomObama_panel$Level == "Circuit" & jnomObama_panel$lost_control == 0, ])
mod_jnom_d_lost <- felm(log_word ~ noFilibuster + same_state  | speakerid2 | 0 | congress, data = jnomObama_panel[jnomObama_panel$Level == "District" & jnomObama_panel$lost_control == 0, ])

stargazer(mod_jnom_lost, mod_jnom_c_lost, mod_jnom_d_lost,
          type = "text",
          omit.stat = c("adj.rsq", "f", "ser"),
          add.lines = list(c("Senator FE", "Yes", "Yes", "Yes"),
                           c("Unique Senator", "155", "155", "155"),
                           c("Unique Nominee", "323", "53", "250")))



# Table A.16: Placebo Test of Legislative Discussion of Judicial Nominees
#            (Suppose a Filibuster Rule Change in Nov 21, 2005)
mod_jnom_bush <- felm(log_word ~ noFilibuster + Level + same_state | speakerid2 | 0 | congress, data = jnomBush_panel)
mod_jnom_c_bush <- felm(log_word ~ noFilibuster + same_state | speakerid2 | 0 | congress, data = jnomBush_panel[jnomBush_panel$Level == "Circuit", ])
mod_jnom_d_bush <- felm(log_word ~ noFilibuster + same_state | speakerid2 | 0 | congress, data = jnomBush_panel[jnomBush_panel$Level == "District", ])


stargazer(mod_jnom_bush, mod_jnom_c_bush, mod_jnom_d_bush,
         type = "text",
          omit.stat = c("adj.rsq", "f", "ser"),
          add.lines = list(c("Senator FE", "Yes", "Yes", "Yes"),
                           c("Unique Senator", "153", "153", "153"),
                           c("Unique Nominee", "322", "61", "261")))















